package edu.sctu.xialei.june.day20150623one.http.util;

import java.io.*;
import java.net.HttpURLConnection;
import java.net.URL;

/**
 * Created by Administrator on 2015/6/23.
 */
public class UrlMethods {

    public String urlGET(String urlPath) throws IOException {

        URL url = new URL(urlPath);
        HttpURLConnection httpURLConnection = (HttpURLConnection) url.openConnection();

        httpURLConnection.setRequestMethod("GET");
        httpURLConnection.setDoOutput(true);
        httpURLConnection.setDoInput(true);

        InputStream inputStream = (InputStream) httpURLConnection.getInputStream();
        byte[] value = new byte[1];
        String json = "";

        while(inputStream.read(value) != -1) {
            json = json + new String(value,"utf-8");
        }

        inputStream.close();

        return json;
    }
}
